package com.tanguy.user.ui.hotel.activity

import android.support.v4.view.ViewPager
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import com.tanguy.user.R
import com.tanguy.user.base.ImmersionTitleActivity
import com.tanguy.user.custom.FrescoImageLoader
import com.youth.banner.Banner
import com.youth.banner.BannerConfig
import org.jetbrains.anko.find

/**
 * Created by dab on 2017/10/13 0013 09:31
 *  酒店详情
 */
class HotelDetailsActivity : ImmersionTitleActivity() {
    override fun setContentViewRes(): Int = R.layout.activity_hotel_details
    lateinit var banner: Banner
    override fun initView() {
        super.initView()
        find<View>(R.id.view_status_bar).visibility = View.GONE
        titleBar.visibility = View.GONE
        initBanner()

    }

    /**
     * 初始化banner相关
     */
    private fun initBanner() {

        banner = find<Banner>(R.id.banner).apply {
            setBannerStyle(BannerConfig.NOT_INDICATOR)
            setImageLoader(FrescoImageLoader())
            setDelayTime(5000)
        }
        val linearLayout = find<LinearLayout>(R.id.layout_indicator)
        val viewPager = banner.find<ViewPager>(com.youth.banner.R.id.bannerViewPager)
        viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
            override fun onPageSelected(position: Int) {
                upIndicator(position, linearLayout)
            }
        })
        val arrayListOf = arrayListOf(R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher)
        for (i in 0..arrayListOf.size - 1) {
            LayoutInflater.from(this).inflate(R.layout.view_banner_indicator, linearLayout)
        }
        banner.setImages(arrayListOf)
        banner.start()
    }

    /**
     * 修改指示器的样式
     */
    fun upIndicator(position: Int, linearLayout: LinearLayout) {
        val pos = position % linearLayout.childCount
        for (i in 0..linearLayout.childCount) {
            linearLayout.getChildAt(i)?.find<View>(R.id.view_select)?.visibility = if (pos == i) View.VISIBLE else View.GONE
            linearLayout.getChildAt(i)?.find<View>(R.id.view_no_select)?.visibility = if (pos == i) View.GONE else View.VISIBLE
        }
    }
}